package io.xxx.mario.room.convert;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import io.xxx.mario.room.Room;
import io.xxx.mario.room.api.LeaveRoomRequest;
import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class LeaveRoomRequestConverter implements Converter<LeaveRoomRequest, Room> {

    @Override
    public Room convert(@NonNull LeaveRoomRequest source) {
        LocalDateTime now = LocalDateTime.now();

        Room room = new Room();
        room.setId(IdWorker.getId());
        room.setOutId(source.getRoomOutId());
        room.setName(source.getRoomName());
        room.setMemberCount(source.getMemberCount());
        room.setRobotWxId(source.getRobotWxId());
        room.setRobotNickName(source.getRobotNickName());
        room.setCreatedTime(now);
        room.setUpdatedTime(now);

        return room;
    }
}
